package main.Q2301_2400;

public class Q2391_2400 {
	public static void main(String[] args) {
		System.out.println("Question2391：收集垃圾的最少总时间");
		System.out.println("Question2392：");
		System.out.println("Question2393：");
		System.out.println("Question2394：");
		System.out.println("Question2395：");
		System.out.println("Question2396：");
		System.out.println("Question2397：");
		System.out.println("Question2398：");
		System.out.println("Question2399：");
		System.out.println("Question2400：");
	}
}

class Question2391 {
	public int garbageCollection(String[] garbage, int[] travel) {
		int res = 0, m = 0, p = 0, g = 0;
		int[] pre = new int[travel.length + 1];
		pre[0] = 0;
		for (int i = 1; i <= travel.length; i++) {
			pre[i] = pre[i - 1] + travel[i - 1];
		}
		for (int i = 0; i < garbage.length; i++) {
			for (char c : garbage[i].toCharArray()) {
				if (c == 'M') {
					res += pre[i] - pre[m] + 1;
					m = i;
				}
				if (c == 'P') {
					res += pre[i] - pre[p] + 1;
					p = i;
				}
				if (c == 'G') {
					res += pre[i] - pre[g] + 1;
					g = i;
				}
			}
		}
		return res;
	}
}